package com.lp.service.impl;

import com.lp.dao.TeacherDao;
import com.lp.po.PagingVO;
import com.lp.po.Teacher;
import com.lp.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Resource
    private TeacherDao teacherDao;
    @Override
    public int getCount() throws Exception {
        return teacherDao.count();
    }
    @Override
    public int getCountByName(String username) throws Exception {
        return teacherDao.countByName(username);
    }
    @Override
    public List<Teacher> findAllTeacher(Integer toPageNo) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Teacher> list=teacherDao.findAllTeacher(pagingVO);
        return list;
    }

    @Override
    public List<Teacher> findByTeacherName(Integer toPageNo,String username) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Teacher> list=teacherDao.findByTeacherName(pagingVO.getTopageNo(),pagingVO.getPageSize(),username);
        return list;
    }

    @Override
    public boolean save(Teacher teacher) {
        Teacher tea = teacherDao.selectTeacherUseid(teacher.getUserid());
        if (tea == null) {
            teacherDao.insert(teacher);
            return true;
        }
        return false;
    }

    @Override
    public Teacher findById(Integer userid) {
        return teacherDao.findByUserid(userid);
    }

    @Override
    public void updataById(Integer userid, Teacher teacher) throws Exception {
        teacherDao.updateByPrimaryKey(teacher);
    }

    @Override
    public void removeById(Integer userid) {
        teacherDao.removeById(userid);
    }


    /*小程序模块*/
    @Override
    public List<Teacher> wxfindAllTeacher(Integer collegeid) {
        List<Teacher> list=teacherDao.wxfindAllTeacher(collegeid);
        return list;
    }

    @Override
    public List<Teacher> wxFindTeacherWithDepID(Integer collegeid) {
        return teacherDao.wxFindTeacherWithDepID(collegeid);
    }
}
